<template>
	<view class="pb40">
		<view class="register mb24">
			<view class="back">
				<image src="../../static/login/log-left.png" mode="" @click="gotoWallet" class="leftarrow"></image>
				<view class="f17 white fw0">{{i18n.tibi}}</view>
				<navigator class="chrecord f14 grcolor" :url="'./extractrec?coin=' + array[index1]">{{i18n.tbjl}}</navigator>
			</view>
		</view>
		<!-- <view class="moneyname grcolor mgt20 f14">币种</view> -->
		<view class="moneybox pd15 mgt20 fsc">
			<view class="f28 uni-list-cell-db fsc white" style="width: 100%;line-height: 24px;">
				<view class="uni-input f15">{{ array[index1] }}</view>
				<picker @change="bindPickerChange" :value="index1" :range="array">
					<text class="f14 textcolor">
						{{i18n.xzbz}}
					<image class="ml9" src="../../static/grarrow.png" mode="" style="width: 12rpx; height: 20rpx;"></image>
					</text>
					
				</picker>
			</view>
		</view>
		<view class="moneyname mt15 f14 white">{{i18n.sl}}</view>
		<view class="moneybox pd15 mt9 fsc">
			<view class=""><input class="f15" type="number" v-model="number"  value="" :placeholder="i18n.srtbsl" /></view>
			<view class="f14" style="color: #308AE4;" @click="totalnumber">{{i18n.quanbu}}</view>
		</view>
		<text class="textcolor f12 mt5 ml15">{{i18n.ky}}{{array[index1]}}：{{freeMoney}}</text>
		
		
		<view class="moneyname mt15 f14 white">{{i18n.dzqb}}</view>
		<view class="moneybox pd15 mgt20 fsc">
			<view class=""><input style="width: 500rpx;" class="f15" type="text" :placeholder="i18n.srdzqb" v-model="address" /></view>
			<image src="../../static/scan.png" mode="" @click="scanCode"></image>
		</view>
		<view class="moneyname white mt15 f14">{{i18n.beizhu}}</view>
		<view class="moneybox pd15 mgt20 fsc">
			<view class=""><input class="f15" type="text" value="" v-model="remark" :placeholder="i18n.qsrbz" /></view>
		</view>
		<view class="moneyname white mt15 f14">
			{{i18n.sxf}}
			<text class="textcolor">（{{rate}}%）</text>
		</view>
		<view class="moneybox pd15 mgt20 fsc">
			<view class="">
				<input class="f15" type="text" disabled="true" value="0" placeholder="0" v-model="calcRate" />
			</view>
			<text class="f14 textcolor">USDT</text>
		</view>
		<view class="moneyname white mt15 f14">{{i18n.zfmm}}</view>
		<view class="moneybox pd15 mgt20 fsc">
			<view class=""><input class="f15" type="password" value="" maxlength="6" v-model="payword" :placeholder="i18n.qsrmm" /></view>
		</view>
		<view class="okextract mgt20" @click="withdraw">{{i18n.tibi}}</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			nikeName: '',
			index: 0,
			array: [],
			index1: 0,
			number: '', 
			address: '',
			remark: '',
			rate: '',
			payword: '',
			smsCode: '',
			emailCode: '',
			show: false,
			tel: '',
			code: '',
			email: '',
			emailcode: '',
			Mark: false,
			maxNumberDay:"", // 单日最大提币数量
			maxNumber:"", // 最大提币数量
			mineNumber:"", // 最小提币数量
			freeMoney:0, // 当前币种用户可用余额
		};
	},
	onLoad() {
		this.getCoin()
	},
	onShow() {
	},
	computed:{
		calcRate(){
			let { accMul } = this.$utils.num
			let r = accMul(this.number , this.rate / 100);
			return r;
		},
		i18n() {
			return this.$t('ecology');
		}
	},
	methods: {
		
		getCoin(){			
			 this.$http.post("wallet.mywallet").then(res=>{
				res.data.walletList.forEach((item,index1)=>{
					this.array[index1] = item.coin
				})
				this.getMoney()
			})
		},
		getMoney(){
			let params = {
				coin: this.array[this.index1]
			};
			console.log(params)
			this.$http.post('wallet.getCoinInfo', params).then(res => {
				// console.log(res);
				this.rate = res.data.minerFee; // 手续费
				this.maxNumberDay=res.data.maxNumberDay // 每天 最大提币量
				this.maxNumber=res.data.maxNumber // 每次最大提币量
				this.mineNumber=res.data.mineNumber // 每次最小提币量
				this.freeMoney = res.data.money;
			});
		},
		selectcharge(index) {
			// console.log(index);
			this.index = index;
		},
		bindPickerChange: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			this.index1 =e.target.value;
			this.number=""
			this.getMoney()
		},
		gotoWallet() {
			uni.reLaunch({
				url: './wallet'
			});
		},
		totalnumber() {
			// let params = {
			// 	coin: this.array[this.index1]
			// };
			// this.$http.post('wallet.getCoinInfo', params).then(res => {
			// 	// console.log(res);
			// 	this.number = res.data.maxNumber;
			// });
			this.number = this.freeMoney;
		},
		withdraw() {
			if(this.number <= 0 ){
				uni.showToast({
					title:this.$t('ecology').tbslcw,
					icon: "none",
				})
				return false;
			}
			if(this.address == ''){
				uni.showToast({
					title:this.$t('ecology').dzqbbn,
					icon: "none",
				})
				return false;
			}
			if(this.payword == ''){
				uni.showToast({
					title:this.$t('ecology').srzfmm,
					icon: "none",
				})
				return false;
			}
			let params = {
				coin: this.array[this.index1], // 币种名称
				money: this.number, // 提币数量
				password: this.payword, // 支付密码
				toAddress: this.address, // 提币地址
				remarks: this.remark, // 备注
				phoneId: this.UID, // 设备唯一id
			};
			this.$http.post('wallet.withdraw', params).then(res => {
				console.log(res);
				if (res.code == 200) {
					setTimeout(() => {
						uni.navigateTo({
							url: './extractsuccess'
						});
					}, 500);
				}
			});
		},
		scanCode() {
			let that = this;
			uni.scanCode({
				success: function(res) {
					// console.log(res);
					that.address = res.result;
				}
			});
		}
	}
};
</script>

<style lang="less">
	.textcolor{
		color:#586471;
	}
	.fw0{
		font-weight: 0 !important;
	}
	.buttonable {
		width: 180rpx;
		height: 56rpx;
		line-height: 56rpx;
		text-align: center;
		opacity: 1;
		background: #1372df;
		border-radius: 6rpx;
		color: #fff;
	}
	.buttondisable {
		width: 180rpx;
		height: 56rpx;
		line-height: 56rpx;
		text-align: center;
		opacity: 1;
		background: #efefef;
		border-radius: 6rpx;
		color: #6d7278;
	}
.popupcontent {
	font-size: 28rpx;
	line-height: 44rpx;
	overflow-y: scroll;
	height: 600rpx;
	text-align: left;
	padding: 30rpx;
	width: 690rpx;
	display: block;
}
.itembox {
	width: 690rpx;
	padding: 0 0rpx 36rpx 0rpx;
	border-bottom: 2rpx solid #ccc;
	margin-left: auto;
	margin-right: auto;
	
	input {
		text-align: right;
	}
}
page {
	padding-bottom: 80rpx;
}
.register {
	margin-top: 60rpx;
	.back {
		justify-content: center;
		align-items: center;
		display: flex;
		font-size: 34rpx;
		margin-left: 30rpx;
		position: relative;
		.leftarrow {
			position: absolute;
			left: 0;
			top: 0;
			width: 32rpx;
			height: 32rpx;
		}
	}
	.chrecord {
		position: absolute;
		top: 4rpx;
		right: 0;
		margin-right: 30rpx;
		color:#586471;
	}
}
.moneyname {
	padding-left: 30rpx;
}
.moneybox {
	width: 630rpx;
	height: 45rpx;
	opacity: 1;
	background: #121d2c;
	border-radius: 16rpx;
	margin-left: auto;
	margin-right: auto;
	image {
		width: 36rpx;
		height: 36rpx;
	}
}
.okextract {
	width: 690rpx;
	height: 88rpx;
	line-height: 88rpx;
	opacity: 1;
	background: #1372df;
	border-radius: 8rpx;
	color: #fff;
	text-align: center;
	font-size: 32rpx;
	margin-left: auto;
	margin-right: auto;
}
// .uni-picker-container{
// 	color: #828282;
// 	font-size: 24rpx;
// }
</style>
